<?php

/*

  Action	$7

  Trash a card from your hand. Gain a card costing up to $3 more than the trashed card.

 */

class Expand extends Card implements iAction, iKingdom, iProsperity {

    public function __construct() {
        parent::__construct("Expand", 7);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Trash a card from your hand. Gain a card costing up to $3 more than the trashed card.");
    }
    
    public function play(Game $game, $isRealCard) {

        $playHand = $game->getPlayHand();
        if (sizeof($playHand) > 0) {
            $playHand = getUniqueCards($playHand);
			if (sizeof($playHand) > 1) {
				$output = MySocket::GetUserReply($game,  Input_ChooseOne, $playHand, 1, 1, null, "Choose card to trash");
				$card_name = $output[0];
			}
			else {
				$card_name = $playHand[0];
			}
			
            $old_card = $game->moveCardFromPileToPile($card_name, PlayHand, Trash);
            ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($old_card), "trashes " . ScreenDisplay::$LMSG);
            
            $price = $old_card->getPrice($game);
            $new_price = $price->add(3);
            $optional_cards = $game->getBoardCardsByPrice(new Price(0), $new_price);

            $output = MySocket::GetUserReply($game,  Input_ChooseOne, $optional_cards, 1, 1, null, "Choose a card to gain");
            $card_name = $output[0];
            $new_card= $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile);
             ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($new_card), " and gains " . ScreenDisplay::$LMSG);
        }
		else {
		    ScreenDisplay::addScreenMessage($game, true, "trash nothing", "trashes nothing");
		}
        $game->cardActionFinished();
        return true;
    }

}

?>